package org.dingfugui.triple.context;

import org.dingfugui.triple.context.producer.DefaultExecuteHandler;
import org.dingfugui.triple.context.producer.ExecuteHandler;
import org.dingfugui.triple.protocol.Protocol;
import org.dingfugui.triple.protocol.binary.aio.AioProtocol;

import java.io.IOException;

/**
 * Created by fugui.ding on 2015/4/1.
 */
public class DefaultServiceContext extends AbstractProducerContext {

    /* 生产者方法执行器 */
    protected ExecuteHandler executeHandler = new DefaultExecuteHandler(this);
    /* 远程服务协议 */
    protected Protocol protocol;

    public DefaultServiceContext() {
        protocol = new AioProtocol(executeHandler);
    }

    public DefaultServiceContext(int port) {
        protocol = new AioProtocol(port, executeHandler);
    }

    @Override
    public void start() throws IOException {
        protocol.getAcceptor().accept();
    }

    public Protocol getProtocol() {
        return protocol;
    }

    public void setProtocol(Protocol protocol) {
        this.protocol = protocol;
    }
}



